home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifFrameBorder.java < prev    next >
Text File  |  1998-06-30  |  7KB  |  234 lines

  1. /*
  2.  * @(#)MotifFrameBorder.java    1.5 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.plaf.motif;
  21.  
  22. import java.awt.Graphics;
  23. import java.awt.Dimension;
  24. import java.awt.Rectangle;
  25. import java.awt.Color;
  26. import java.awt.Insets;
  27.  
  28. import java.awt.*;
  29. import java.beans.*;
  30.  
  31. import com.sun.java.swing.*;
  32. import com.sun.java.swing.border.AbstractBorder;
  33. import com.sun.java.swing.plaf.UIResource;
  34.  
  35. /**
  36.  * <p>
  37.  * Warning: serialized objects of this class will not be compatible with
  38.  * future swing releases.  The current serialization support is appropriate
  39.  * for short term storage or RMI between Swing1.0 applications.  It will
  40.  * not be possible to load serialized Swing1.0 objects with future releases
  41.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  42.  * baseline for the serialized form of Swing objects.
  43.  *
  44.  * @version 1.5 02/02/98
  45.  * @author unknown
  46.  */
  47.  
  48. public class MotifFrameBorder extends AbstractBorder implements UIResource {
  49.  
  50.     JComponent jcomp;
  51.     Color frameHighlight;
  52.     Color frameColor;
  53.     Color frameShadow;
  54.  
  55.     // The width of the border
  56.     public final static int BORDER_SIZE = 5;
  57.  
  58.     /** Constructs an FrameBorder for the JComponent <b>comp</b>.
  59.       */
  60.     public MotifFrameBorder(JComponent comp) {
  61.         jcomp = comp;
  62.     }
  63.  
  64.     /** Sets the FrameBorder's JComponent.
  65.       */
  66.     public void setComponent(JComponent comp) {
  67.         jcomp = comp;
  68.     }
  69.  
  70.     /** Returns the FrameBorder's JComponent.
  71.       * @see #setComponent
  72.       */
  73.     public JComponent component() {
  74.         return jcomp;
  75.     }
  76.  
  77.     protected Color getFrameHighlight() {
  78.         return frameHighlight;
  79.     }
  80.  
  81.     protected Color getFrameColor() {
  82.         return frameColor;
  83.     }
  84.     
  85.     protected Color getFrameShadow() {
  86.         return frameShadow;
  87.     }
  88.  
  89.     static Insets insets = new Insets(BORDER_SIZE, BORDER_SIZE,
  90.                                       BORDER_SIZE, BORDER_SIZE);
  91.  
  92.     public Insets getBorderInsets(Component c) {
  93.         return insets;
  94.     }
  95.  
  96.    /** Draws the FrameBorder's top border.
  97.      */
  98.     protected boolean drawTopBorder(Component c, Graphics g, 
  99.                                     int x, int y, int width, int height) {
  100.         Rectangle titleBarRect = new Rectangle(x, y, width, BORDER_SIZE);
  101.         if (!g.getClipBounds().intersects(titleBarRect)) {
  102.             return false;
  103.         }
  104.  
  105.         int maxX = width - 1;
  106.         int maxY = BORDER_SIZE - 1;
  107.  
  108.         // Draw frame
  109.         g.setColor(frameColor);
  110.         g.drawLine(x, y + 2, maxX - 2, y + 2);
  111.         g.drawLine(x, y + 3, maxX - 2, y + 3);
  112.         g.drawLine(x, y + 4, maxX - 2, y + 4);
  113.  
  114.         // Draw highlights
  115.         g.setColor(frameHighlight);
  116.         g.drawLine(x, y, maxX, y);
  117.         g.drawLine(x, y + 1, maxX, y + 1);
  118.         g.drawLine(x, y + 2, x, y + 4);
  119.         g.drawLine(x + 1, y + 2, x + 1, y + 4);
  120.  
  121.         // Draw shadows
  122.         g.setColor(frameShadow);
  123.         g.drawLine(x + 4, y + 4, maxX - 4, y + 4);
  124.         g.drawLine(maxX, y + 1, maxX, maxY);
  125.         g.drawLine(maxX - 1, y + 2, maxX - 1, maxY);
  126.  
  127.         return true;
  128.     }
  129.  
  130.     /** Draws the FrameBorder's left border.
  131.       */
  132.     protected boolean drawLeftBorder(Component c, Graphics g, int x, int y, 
  133.                                int width, int height) {
  134.         Rectangle borderRect = 
  135.             new Rectangle(0, 0, getBorderInsets(c).left, height);
  136.         if (!g.getClipBounds().intersects(borderRect)) {
  137.             return false;
  138.         }
  139.  
  140.         int startY = BORDER_SIZE;
  141.  
  142.         g.setColor(frameHighlight);
  143.         g.drawLine(x, startY, x, height - 1);
  144.         g.drawLine(x + 1, startY, x + 1, height - 2);
  145.  
  146.         g.setColor(frameColor);
  147.         g.fillRect(x + 2, startY, x + 2, height - 3);
  148.  
  149.         g.setColor(frameShadow);
  150.         g.drawLine(x + 4, startY, x + 4, height - 5);
  151.  
  152.         return true;
  153.     }
  154.  
  155.     /** Draws the FrameBorder's right border.
  156.       */
  157.     protected boolean drawRightBorder(Component c, Graphics g, int x, int y, 
  158.                                 int width, int height) {
  159.         Rectangle borderRect = new Rectangle(
  160.             width - getBorderInsets(c).right, 0,
  161.             getBorderInsets(c).right, height);
  162.         if (!g.getClipBounds().intersects(borderRect)) {
  163.             return false;
  164.         }
  165.  
  166.         int startX = width - getBorderInsets(c).right;
  167.         int startY = BORDER_SIZE;
  168.  
  169.         g.setColor(frameColor);
  170.         g.fillRect(startX + 1, startY, 2, height - 1);
  171.  
  172.         g.setColor(frameShadow);
  173.         g.fillRect(startX + 3, startY, 2, height - 1);
  174.  
  175.         g.setColor(frameHighlight);
  176.         g.drawLine(startX, startY, startX, height - 1);
  177.  
  178.         return true;
  179.     }
  180.  
  181.     /** Draws the FrameBorder's bottom border.
  182.       */
  183.     protected boolean drawBottomBorder(Component c, Graphics g, int x, int y, 
  184.                                  int width, int height) {
  185.         Rectangle    borderRect;
  186.         int     marginHeight, startY;
  187.  
  188.         borderRect = new Rectangle(0, height - getBorderInsets(c).bottom,
  189.                                   width, getBorderInsets(c).bottom);
  190.         if (!g.getClipBounds().intersects(borderRect)) {
  191.             return false;
  192.         }
  193.  
  194.         startY = height - getBorderInsets(c).bottom;
  195.  
  196.         g.setColor(frameShadow);
  197.         g.drawLine(x + 1, height - 1, width - 1, height - 1);
  198.         g.drawLine(x + 2, height - 2, width - 2, height - 2);
  199.  
  200.         g.setColor(frameColor);
  201.         g.fillRect(x + 2, startY + 1, width - 4, 2);
  202.  
  203.         g.setColor(frameHighlight);
  204.         g.drawLine(x + 5, startY, width - 5, startY);
  205.  
  206.         return true;
  207.     }
  208.  
  209.     // Returns true if the associated component has focus.
  210.     protected boolean isActiveFrame() {
  211.         return jcomp.hasFocus();
  212.     }
  213.  
  214.     /** Draws the FrameBorder in the given Rect.  Calls
  215.       * <b>drawTitleBar</b>, <b>drawLeftBorder</b>, <b>drawRightBorder</b> and
  216.       * <b>drawBottomBorder</b>.
  217.       */
  218.     public void paintBorder(Component c, Graphics g, 
  219.                             int x, int y, int width, int height) {
  220.         if (isActiveFrame()) {
  221.             frameColor = UIManager.getColor("activeCaptionBorder");
  222.         } else {
  223.             frameColor = UIManager.getColor("inactiveCaptionBorder");
  224.         }
  225.         frameHighlight = frameColor.brighter();
  226.         frameShadow = frameColor.darker().darker();
  227.  
  228.         drawTopBorder(c, g, x, y, width, height);
  229.         drawLeftBorder(c, g, x, y, width, height);
  230.         drawRightBorder(c, g, x, y, width, height);
  231.         drawBottomBorder(c, g, x, y, width, height);
  232.     }
  233. }
  234.